import React from "react"

export default class ComponentLife extends React.Component {

    constructor(props) {
        super(props);
        // 定义此时的状态变量
        this.state = {
            count:10
        }
    }
    componentWillMount() {
        console.log("componentWillMount");
    }
    componentDidMount() {
        console.log("componentDidMount");
    }
    shouldComponentUpdate() {
        return true;
    }
    componentWillUpdate(){
        console.log(" componentwillUpdate");
    }
    componentDidUpdate() {
        console.log("componentwillUpdate");
    }
    componentWillReceiveProps() {
        console.log("componentwillReceiveProps");
    }
    componentWllUnmount() {
        console.log("componentwillunmount");
    }
    async Xiugaifun(){
        await this.setStateAsync({count:this.state.count+1});
    }
    setStateAsync(state){
        return new Promise((re) => {
            this.setState(state,re)
        })
    }
    render(){
        const {count} = this.state
        return(
            <div>
                生命周期函数:{count}
                <button onClick={this.Xiugaifun.bind(this)}>修改</button>
            </div>
        )
    }

}